package com.yujie.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yujie.domain.Dictionary;
import com.yujie.domain.query.DictionaryQuery;
import com.yujie.service.DictionaryService;
import com.yujie.util.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 字典表(Dictionary)表控制层
 *
 * @author wangyujie
 * @since 2023-08-14 20:33:28
 */
@RestController
@RequestMapping("dictionary")
public class DictionaryController {

    /**
     * 服务对象
     */
    @Resource
    private DictionaryService dictionaryService;

    /**
     * 分页查询所有数据
     */
    @PostMapping("/list")
    public R page(@RequestParam(value = "size", defaultValue = "10") Integer size, @RequestParam(value = "current", defaultValue = "0") Integer current, Dictionary query) {
        QueryWrapper<Dictionary> queryWrapper = new QueryWrapper<>();
        queryWrapper.setEntity(query);
        Page<Dictionary> page = new Page();
        page.setCurrent(current);
        page.setSize(size);
        return R.ok().setData(this.dictionaryService.page(page, queryWrapper));
    }


    /**
     * 新增数据
     */
    @PostMapping("/insert")
    public R save(@RequestBody Dictionary query) {
        return R.ok().setData(this.dictionaryService.save(query));
    }

    /**
     * 修改数据
     */
    @PostMapping("/update")
    public R updateById(@RequestBody Dictionary query) {
        return R.ok().setData(this.dictionaryService.updateById(query));
    }

    /**
     * 单条/批量删除数据
     */
    @PostMapping("/delete")
    public R delete(@RequestBody List<Long> id) {
        return R.ok().setData(this.dictionaryService.removeByIds(id));
    }
}

